package com.hbwxz.compareprice;

import com.hbwxz.utils.CommonUtils;

/**
 * 模拟 Http请求访问第三方平台获取商品价格信息
 *
 * @author shenzw
 * @date 2023/12/18
 */
public class HttpRequest {

    /**
     * 模拟获取价格耗时
     */
    public static void mockCostTimeOperation() {
        CommonUtils.sleepSecond(1);
    }

    /**
     * 获取淘宝平台的商品价格
     *
     * @param productName 商品名称
     * @return PriceResult
     */
    public static PriceResult getTbPriceResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取淘宝上【%s】价格", productName));
        mockCostTimeOperation();
        PriceResult tBaoPriceResult = new PriceResult()
                .setPlatform("淘宝")
                .setPrice(5199);
        CommonUtils.printThreadLog(String.format("淘宝价格为%d", 5199));
        return tBaoPriceResult;
    }


    /**
     * 获取淘宝平台的优惠
     *
     * @param productName 商品名称
     * @return int
     */
    public static int getTbDiscountResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取淘宝上【%s】优惠", productName));
        mockCostTimeOperation();
        CommonUtils.printThreadLog(String.format("淘宝优惠为：%d", -200));
        return 200;
    }

    /**
     * 获取京东平台的商品价格
     *
     * @param productName 商品名称
     * @return PriceResult
     */
    public static PriceResult getJdPriceResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取京东上【%s】价格", productName));
        mockCostTimeOperation();
        PriceResult tBaoPriceResult = new PriceResult()
                .setPlatform("京东")
                .setPrice(5299);
        CommonUtils.printThreadLog(String.format("京东价格为%d", 5299));
        return tBaoPriceResult;
    }


    /**
     * 获取京东平台的优惠
     *
     * @param productName 商品名称
     * @return int
     */
    public static int getJdDiscountResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取京东上【%s】优惠", productName));
        mockCostTimeOperation();
        CommonUtils.printThreadLog(String.format("京东优惠为：%d", -150));
        return 150;
    }

    /**
     * 获取拼多多平台的商品价格
     *
     * @param productName 商品名称
     * @return PriceResult
     */
    public static PriceResult getPddPriceResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取拼多多上【%s】价格", productName));
        mockCostTimeOperation();
        PriceResult tBaoPriceResult = new PriceResult()
                .setPlatform("拼多多")
                .setPrice(5399);
        CommonUtils.printThreadLog(String.format("拼多多价格为%d", 5399));
        return tBaoPriceResult;
    }


    /**
     * 获取拼多多平台的优惠
     *
     * @param productName 商品名称
     * @return int
     */
    public static int getPddDiscountResult(String productName) {
        CommonUtils.printThreadLog(String.format("获取拼多多上【%s】优惠", productName));
        mockCostTimeOperation();
        CommonUtils.printThreadLog(String.format("拼多多优惠为：%d", -5300));
        return 5300;
    }

}
